package com.octopus.kernal.ui.element;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.context.i18n.LocaleContextHolder;

@SuppressWarnings("serial")
public class BaseElement implements Serializable{

	private String id;
	
	private String name;
	
	private String description;
	
	private String onfocus;
	
	private String onclick;
	
	private String cssclass;
	
	private String style;
	
	private Boolean disabled = false;
	
	private Boolean readonly = false;
	
	private Object value;
	
	private HttpServletRequest request;
	
	public static String getTranslationValue(String value){
		if(value == null)
			return null;
		String locale = LocaleContextHolder.getLocale().getLanguage();
		if(locale.equals("en")){
			if(value.indexOf("<en>") != -1 && value.indexOf("</en>") != -1){
				return value.substring(value.indexOf("<en>") + 4, value.indexOf("</en>"));
			}
		}else if(locale.equals("zh")){
			if(value.indexOf("<zh>") != -1 && value.indexOf("</zh>") != -1){
				return value.substring(value.indexOf("<zh>") + 4, value.indexOf("</zh>"));
			}
		}
		return value;
	}

	@XmlAttribute
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@XmlAttribute
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@XmlAttribute
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@XmlAttribute
	public String getOnfocus() {
		return onfocus;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	@XmlAttribute
	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	@XmlAttribute
	public String getCssclass() {
		return cssclass;
	}

	public void setCssclass(String cssclass) {
		this.cssclass = cssclass;
	}

	@XmlAttribute
	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	@XmlAttribute
	public Boolean isReadonly() {
		return readonly;
	}
	
	public Boolean getReadonly() {
		return readonly;
	}

	public void setReadonly(Boolean readonly) {
		this.readonly = readonly;
	}
	
	@XmlAttribute
	public Boolean isDisabled() {
		return disabled;
	}
	
	public Boolean getDisabled() {
		return disabled;
	}

	public void setDisabled(Boolean disabled) {
		this.disabled = disabled;
	}
	
	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public String toString(){
		return "";
	}

	@XmlTransient
	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	
}
